//
//  AddInterestAlertView.m
//  League
//
//  Created by 崔璨 on 2018/1/30.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "AddInterestAlertView.h"
#import "BaseViewController.h"
#define kBKColor [UIColor colorWithRed:243/255.0 green:242/255.0 blue:243/255.0 alpha:1]
#define kCancelTextColor [UIColor colorWithRed:190/255.0 green:190/255.0 blue:190/255.0 alpha:1]
@implementation AddInterestAlertView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame=frame;
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
        [self setupUI];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeView)];
        singleTap.delegate=self;
        [self addGestureRecognizer:singleTap];
    }
    return self;
}
-(void)setupUI
{
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width*0.8, self.height/3)];
    self.bgView.center = CGPointMake(self.width/2, self.height/2);
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 8;
    [self addSubview:self.bgView];
    
    self.headLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 44)];
    self.headLab.font = [UIFont systemFontOfSize:18];
    self.headLab.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview: self.headLab];
    
    self.textFileOne = [[UITextField alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.headLab.frame), self.bgView.width - 20, 44)];
    self.textFileOne.font = [UIFont systemFontOfSize:14];
    self.textFileOne.textAlignment = NSTextAlignmentCenter;
    self.textFileOne.layer.masksToBounds = YES;
    self.textFileOne.layer.cornerRadius = 5;
    self.textFileOne.layer.borderWidth = 1;
    self.textFileOne.layer.borderColor = [kBKColor CGColor];
    [self.bgView addSubview:self.textFileOne];
    
    self.lineOne = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.textFileOne.frame) + 20, self.bgView.width, 1)];
    self.lineOne.backgroundColor = kBKColor;
    [self.bgView addSubview:self.lineOne];
    
    self.addBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lineOne.frame) + 1, self.bgView.width, 44)];
    [self.addBtn setTitleColor:kAppColor forState:UIControlStateNormal];
    self.addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.bgView addSubview:self.addBtn];
    
    self.lineTwo = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.addBtn.frame), self.bgView.width, 1)];
    self.lineTwo.backgroundColor = kBKColor;
    [self.bgView addSubview:self.lineTwo];
    
    self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.lineTwo.frame) + 1, self.bgView.width, 44)];
    [self.cancelBtn setTitleColor:kCancelTextColor forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.cancelBtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchDown];
    [self.bgView addSubview:self.cancelBtn];
    
    self.bgView.bounds = CGRectMake(0, 0, self.width*0.8, CGRectGetMaxY(self.cancelBtn.frame));
}
-(void)removeView
{
    [self removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    
    if (touch.view !=self){
        
        return NO;
        
    }
    
    return YES;
    
}
@end
